﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Utils.Common;
using ZK.BLL;
using ZK.Entity;

namespace ZK.Client.WinForm
{
    public partial class FrmVDJTemplateEdit : Form
    {
        public FrmVDJTemplateEdit()
        {
            InitializeComponent();
        }

        public VDJTemplate VDJTemplate { get; set; }

        private void FrmVDJTemplateEdit_Load(object sender, EventArgs e)
        {
 
            cmbFontHigh.DataSource = new string[] { "12-high", "16-high", "20-high", "24-high", "25-high", "26-high", "34-high" };
            if (VDJTemplate != null)
            {
                txtTemplateName.Text = VDJTemplate.TemplateName;
                uc_Delay.Value = VDJTemplate.Delay;
                uc_CharacterGap.Value = VDJTemplate.CharacterGap;
                uc_Width.Value = VDJTemplate.CharWidth;
                uc_Height.Value = VDJTemplate.CharHeight;
                cmbFontHigh.SelectedIndex = cmbFontHigh.FindString(VDJTemplate.FontHigh);
            }
            else {
                VDJTemplate = new VDJTemplate();
            }
 
        }

      
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSure_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtTemplateName.Text.Trim()))
            {
                MessageBox.Show("请输入模板名称！");
                return;
            }


            if (cmbFontHigh.SelectedIndex == -1)
            {
                MessageBox.Show("请先选择光栅！");
                return;
            }

            VDJTemplate.TemplateName = txtTemplateName.Text.Trim();
            VDJTemplate.Delay = uc_Delay.Value;
            VDJTemplate.CharacterGap = uc_CharacterGap.Value;
            VDJTemplate.CharWidth = uc_Width.Value;
            VDJTemplate.CharHeight = uc_Height.Value;
            VDJTemplate.FontHigh = cmbFontHigh.Text.Trim();

            if (string.IsNullOrEmpty(VDJTemplate.Id))
            {

                VDJTemplate.Id = VDJTemplateBLL.Instance.GetNewID();
                if (VDJTemplateBLL.Instance.Insert(VDJTemplate))
                {
                    this.DialogResult = DialogResult.OK;

                    this.Close();
                }
                else
                {
                    MessageBox.Show("保存失败");
                }
            }
            else {

                 VDJTemplateBLL.Instance.DeleteById(VDJTemplate.Id);
                if (VDJTemplateBLL.Instance.Insert(VDJTemplate))
                {
                    this.DialogResult = DialogResult.OK;

                    this.Close();
                }
                else
                {
                    MessageBox.Show("保存失败");
                }
            }
         
        }

        



    }
}
